package com.example.javademo.Controller;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
@Tag(name = "欢迎接口", description = "欢迎新用户来到页面调试接口")
@RestController
public class HelloController {

    @GetMapping("/hello")
//    public String hello() {
//        return "Hello World";
//    }
    @Operation(
            parameters = @Parameter(name = "name", description = "User name", required = true),
            responses = {
                    @ApiResponse(
                            responseCode = "200",
                            description = "成功",
                            content = @Content(schema = @Schema(implementation = String.class))
                    ),
            }
    )
    public String hello() {
        try {
            // 使用类加载器获取资源的输入流
            InputStream inputStream = getClass().getClassLoader().getResourceAsStream("src/main/static/index.html");
            if (inputStream == null) {
                return "File not found: static/index.html";
            }
            // 读取输入流内容
            return new String(inputStream.readAllBytes(), StandardCharsets.UTF_8);
        } catch (IOException e) {
            return "Failed to read index.html file: " + e.getMessage();
        }
    }
}
